package com.example.db;

import java.util.ArrayList;
import java.util.List;

import com.example.db.core.DBConfig;
import com.example.db.core.DBKit;
import com.example.db.core.DatabaseHelper;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		DBConfig.addModel(User.class);
		List<Class<?>> clazzs = new ArrayList<Class<?>>();
		clazzs.add(User.class);
		DBConfig.init(this);
		
		User user = new User();
		user.setName("abc123");
		user.setEmail("aa@126.com");
		long id = user.save();
		
		DBKit.save(user);
		
		List<User> uList = new User().findAll();
		if(uList != null) {
			Log.d("", "db length: " + uList.size());
			for (int i = 0; i < uList.size(); i++) {
				User u = uList.get(i);
				Log.d("", u.getId() + " - " + u.getName() + " - " + u.getEmail());
			}
		}
		user.setEmail("武则天");
		user.setId((int)id);
		user.update();
		//Log.d("DEL", "" + user.delete());
		Log.d("DEL", "" + new User().delete());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
